package com.zs.ktsms.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/31 下午5:20
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Page<T> {
    private Integer pageNo; //当前页码
    private Integer pageSize; //每页显示的数量
    private Integer totalCount; //总记录数
    private Integer totalPageCount; //总页数
    private List<T> data; //分页的数据

    public void setPageNo(Integer pageNo) {
        if (pageNo < 1) {
            pageNo = 1;
        }
        if (this.totalPageCount >= 1 && this.totalPageCount < pageNo) {
            pageNo = this.totalPageCount;
        }
        this.pageNo = pageNo;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        this.totalPageCount = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize :
                this.totalCount / this.pageSize + 1;
    }
}
